<?php

use Illuminate\Routing\Controller;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/',	array('as'=>'home','uses'=>'HomeController@index'));

Route::post('login', array('as'=>'login',function(){
	
	$user = array(
			'username' => Input::get('username'),
			'password' => Input::get('password')
	);
	
	if (Auth::attempt($user,true)) {
		return Redirect::back();
	}
	
	return Redirect::back()->with('login_message', 'Usuario no valido');;
	
}));

Route::get('logout', array('as'=>'logout',function(){
	
	Auth::logout();
	return Redirect::route('home');

}))->before('auth');

Route::get('facebook',array('as'=>'facebook.login', 'uses'=>'RegistroController@loginWithFacebook'));

Route::group(array('prefix' => 'registro'), function(){
	
	Route::get('/', array('as'=>'registro','uses'=>'RegistroController@index'));
	Route::post('/', array('as'=>'registro.store','uses'=>'RegistroController@store'));
	
});

Route::group(array('prefix' => 'noticias'), function()
{
	Route::get('/',	array('as'=>'noticias','uses'=>'NoticiasController@index'));
	Route::any('/{id}',array('as'=>'noticia.detalle','uses'=>'NoticiasController@noticia'))->where('id', '[0-9]+');
});

Route::group(array('prefix' => 'torneos'), function()
{
	Route::get('/',	array('as'=>'torneos','uses'=>'TorneosController@index'));
	Route::any('{id}',array('as'=>'torneo.detalle','uses'=>'TorneosController@torneo'))->where('id', '[0-9]+');
});

Route::group(array('prefix' => 'cronicas'), function()
{
	Route::get('/',	array('as'=>'cronicas','uses'=>'CronicasController@index'));
	Route::any('/{id}',array('as'=>'cronica.detalle','uses'=>'CronicasController@cronica'))->where('id', '[0-9]+');
});
Route::group(array('prefix' => 'galeria'), function()
{
	Route::get('/',	array('as'=>'galeria','uses'=>'GaleriaController@index'));
	Route::get('/fotos/{id}',array('as'=>'galeria.fotos','uses'=>'GaleriaController@fotostorneo'))->where('id', '[0-9]+');
	Route::get('/videos/{id}',array('as'=>'galeria.videos','uses'=>'GaleriaController@videostorneo'))->where('id', '[0-9]+');
	
});

Route::get('/galeria',	array('as'=>'galeria','uses'=>'GaleriaController@index'));

Route::get('/contacto',	array('as'=>'contacto','uses'=>'ContactoController@index'));

Route::group(array('prefix' => 'perfil'), function()
{
	Route::get('/', array('as'=>'perfil','uses' => 'PerfilController@index'))->before('auth');
	Route::get('/{id}', array('as'=>'perfil.show','uses' => 'PerfilController@show'))->where('id', '[0-9]+');;
	Route::put('/{id}', array('as'=>'perfil.update','uses' => 'PerfilController@update'))->where('id', '[0-9]+');;

});

Route::group(array('prefix'=>'admin','before'=>'auth'), function(){

	$roles=array(
			'redactor'=>4,
			'admin'=>1,
			'usuario'=>'2',
			'admin.torneos'=>3
	);
	
	//Noticias
	Route::resource('noticias','NoticiasAdminController');
	
	//Torneos
	Route::resource('torneos','TorneosAdminController');
	
	Route::resource('torneos-imagenes','TorneosImagenesAdminController');
	Route::resource('torneos-videos','TorneosVideosAdminController');
	
	
	//Cronicas
	Route::resource('cronicas','CronicasAdminController');

	
	//Campos
	Route::resource('campos','CamposAdminController');
	Route::resource('campos-imagenes','CamposImagenesAdminController');

	
	//Usuarios
	Route::resource('users','UsersAdminController');
	
	
});